package dao.impl;


import dao.StaffDao;
import pojo.Staff;
import util.BaseDao;

import java.util.List;

/**
 * @BelongsProject: jdbc_demo
 * @BelongsPackage: dao.impl
 * @Author: Del
 * @CreateTime: 2025-02-26  09:06
 * @Description: TODO
 * @Version: 1.0
 */
public class StaffDaoImpl extends BaseDao implements StaffDao {

    @Override
    public int addStaff(Staff staff) {
        String sql = "insert into staffs(name,age,phone,sta_pos,add_time,update_time) values(?,?,?,?,?,?)";
        return baseUpdate(sql,staff.getName(),staff.getAge(),staff.getPhone(),staff.getStaPos(),staff.getAddTime(),staff.getUpdateTime());
    }

    @Override
    public int deleteStaff(int id) {
        String sql = "delete from staffs where id = ?";
        return baseUpdate(sql,id);
    }

    @Override
    public int updateStaff(Staff staff) {
        String sql = "update staffs set name = ?,age = ?,phone = ?,sta_pos = ?,update_time = ? where id = ?";
        return baseUpdate(sql,staff.getName(),staff.getAge(),staff.getPhone(),staff.getStaPos(),staff.getUpdateTime(),staff.getId());
    }

    @Override
    public Staff queryStaffById(int id) {
        return baseQueryObject(Staff.class,"select id,name,age,phone,sta_pos as staPos, add_time as addTime, update_time as updateTime from staffs where id = ?",id);
    }

    @Override
    public List<Staff> queryStaffs() {
        return baseQuery(Staff.class,"select id,name,age,phone,sta_pos as staPos, add_time as addTime, update_time as updateTime from staffs");
    }
}
